from flask import Blueprint, request, jsonify
from datetime import date
from app.services import TaskService

bp = Blueprint('task', __name__)

@bp.route('/get_tasks/<int:student_id>', methods=['GET'])
def getTasks(student_id):
    """查询学习任务"""
    result = TaskService.generate_daily_tasks(student_id)
    return jsonify(result), result['code']


@bp.route('/<int:student_id>', methods=['GET'])
def get_tasks(student_id):
    """查询学生任务"""
    result = TaskService.get_tasks(student_id)
    return jsonify(result), result['code']

@bp.route('/<int:task_id>', methods=['DELETE'])
def delete_task(task_id):
    """删除任务"""
    result = TaskService.delete_task(task_id)
    return jsonify(result), result['code']

# 修改任务状态
@bp.route('/<int:task_id>', methods=['PUT'])
def update_task(task_id):
    """修改任务状态"""
    result = TaskService.update_task(task_id)
    return jsonify(result), result['code']

# 生成日完成率报表
@bp.route('/report/<int:student_id>', methods=['GET'])
def get_daily_report(student_id):
    """生成日完成率报表"""
    result = TaskService.get_daily_report(student_id)
    return jsonify(result), result['code']

# 生成周完成率报表
@bp.route('/weekly/report/<int:student_id>', methods=['GET'])
def get_weekly_report(student_id):
    """生成周完成率报表"""
    result = TaskService.get_weekly_report(student_id)
    return jsonify(result), result['code']
# 生产遗忘曲线
@bp.route('/forget/curve/<int:student_id>', methods=['GET'])
def get_forget_curve(student_id):
    """生成遗忘曲线"""
    result = TaskService.get_forgetting_curve(student_id)
    return jsonify(result), result['code']

# 获取学生需要学习的每日学习任务
@bp.route('/generate_daily_tasks/<int:student_id>',methods=['GET'])
def get_daily_tasks(student_id):
    """获取学生需要学习的每日学习任务"""
    result = TaskService.generate_daily_tasks(student_id)
    return jsonify(result), result['code']